<template>
  <div>
    <router-link tag="div" :to="{path:'/'}" class='header-abs' v-show="showAbs">
      <div class="iconfont header-back">&#xe624;</div>
    </router-link>
    <div class='header-fixed' v-show="!showAbs" :style="opacityStyle">
      景点详情
      <router-link tag="div" :to="{path:'/'}" class="iconfont header-fixed-back">&#xe624;</router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: "DetailHeader",
  data() {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated() {
    $(window).on('scroll', this.handleScroll)

  },
  deactivated() {
    $(window).off('scroll')
  },
  methods: {
    handleScroll() {
      console.log('scroll');
      const top = $(document).scrollTop()
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  }
}
</script>

<style lang='stylus' scoped>
@import '~styles/varibles.styl';

.header-abs {
  position: absolute;
  left: 0.2rem;
  top: 0.2rem;
  width: 0.8rem;
  line-height: 0.8rem;
  text-align: center;
  height: 0.8rem;
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.8);

  .header-back {
    color: #fff;
    font-size: 0.4em;
  }
}

.header-fixed {
  position: fixed;
  height: $headerHeight;
  line-height: $headerHeight;
  color: #FFF;
  background: $bgColor;
  text-align: center;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99;

  .header-fixed-back {
    position: fixed;
    width: 0.64rem;
    text-align: center;
    font-size: 0.4rem;
    color: #FFF;
    top: 0;
  }
}
</style>
